home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE3 / POWERBASE / DOCS / Ch05-Valid < prev    next >
Text File  |  2001-01-27  |  17KB  |  300 lines

  1. =============================================
  2. Ch 5 − Input Validation and Validation Tables
  3. =============================================
  4.  
  5. Powerbase can apply two kinds of data input validation:
  6.  
  7. •       Character validation
  8. •       Table validation
  9.  
  10. 5.1     Character validation
  11. ----------------------------
  12. This means exercising control over what characters a field will accept. RISC
  13. OS provides the means to allow writable icons to accept only certain
  14. characters, or ranges of characters, and reject others. The disallowed
  15. characters are simply ignored so that attempts to type them have no effect. 
  16.  
  17. If you Shift/double-click on the Powerbase icon the contents of the
  18. application directory will be displayed. In it you will see an ordinary
  19. directory called Resources and inside Resources you will find a file called
  20. ValStrings. You are recommended not to alter this file unless you understand
  21. exactly what you are doing and to keep a copy of the original. Examining it
  22. can, however, give you an insight into the validation process. Look, for
  23. example, at the entry “03 Number”. This refers to field type 3 (Numeric).
  24. The line below is the validation string of the writable icon which makes up
  25. a numeric field. It looks like this:
  26.  
  27.                A0-9.+\- ;Pptr_write,4,4;KD
  28.  
  29. The initial “A” is a command which signifies “Allow” and is the part of the
  30. validation string which especially concerns us. It determines what
  31. characters the field will allow you to type. In this case they are the
  32. numerals 0-9, the decimal point, plus and minus signs and <space>. Why the
  33. back-slash before the minus sign? Because “-” is a special character in an
  34. icon validation string (used, as in this example, to specify a range of
  35. characters) and so are the semicolon, tilde (~) and the backslash itself. To
  36. include any of these four characters in the validation string you must
  37. precede it with a backslash.  The next character is a semicolon which
  38. indicates that a new command follows. 
  39.  
  40. The “P” which comes next is the command “pointer”. “ptr_write” is the name
  41. of the sprite used to represent the mouse pointer when it is over this type
  42. (and many other types) of field. You will have noticed that the usual RISC
  43. OS arrow changes to a blue vertical bar, somewhat resembling the caret, when
  44. over a writable field. “4,4” specifies the “active point” of the pointer.
  45.  
  46. A couple of further examples should be sufficient. “01 Alphanumeric” uses
  47. the same pointer type but the characters accepted are <space> (immediately
  48. after the “A” for “allow”), the upper-case letters A-Z, the lower-case
  49. letters a-z, the numerals 0-9, some common punctuation and the “½”
  50. character. You might want to add to this list. “06 Calculated” uses a
  51. different pointer sprite (ptr_calc, which resembles a pocket calculator) and
  52. has no “Allow” command at all. (You can’t type into this type of field; its
  53. value is calculated from other fields.)
  54.  
  55. 5.2     Validation tables
  56. -------------------------
  57. Table validation is used where a record field is only allowed to have
  58. certain “values”. A manufacturing company, for instance, will have a product
  59. code for every item it makes and a database of customers which the firm
  60. supplies will make use of such codes to identify the items. It is essential
  61. that whoever enters data is prevented from typing a spurious code. This can
  62. be achieved by linking the appropriate field to a validation table. Fields
  63. linked in this way are recognizable by having their text dark green instead
  64. of black. Powerbase will allow you to type invalid data into the field
  65. initially but, when you click the mouse over a new field or type Return, the
  66. linked validation table is scanned to see whether what you entered in the
  67. field is on the allowed list. If it isn’t Powerbase will restore the
  68. previous contents of the field and print an error message.  
  69.  
  70. Validation tables have other uses too. They can have extra columns
  71. containing other data about the products, such as a name and a brief
  72. description, and lists can be printed in which this more informative data
  73. appears instead of the codes.  You can also have Powerbase replace the
  74. typed-in code with a longer, more readable, form immediately on entry.
  75. Provided the substitute data will fit in the field, replacement occurs when
  76. you type Return or click the mouse in another field. If the replacement is
  77. too long then the typed-in data will be unchanged.  This can be a great
  78. timesaver when a lot of data has to be entered.
  79.  
  80. The F.E. college database referred to in 2.2.5 makes extensive use of
  81. validation tables for subjects, courses, tutors and schools of origin. Not
  82. only does this trap typing errors but the data entry is greatly speeded up
  83. when one can type ELL instead of English Language and Literature, yet have
  84.  
  85.                                 - 36 -
  86.  
  87. the latter printed out on a list by selecting the Expand switch in the Print
  88. options window.
  89.  
  90. 5.3     Creating a validation table
  91. -----------------------------------
  92. Choose Create table from the Validation submenu. Give the table a suitable
  93. name and enter the number of rows required. This will be the maximum number
  94. of items on the allowed list. (It is possible to increase the number later
  95. if necessary.) Next place the caret in the first row (row 0) of the
  96. scrolling list and enter the width (in characters) and the heading
  97. (optional) for the first column of the validation table. 
  98.  
  99. If the table is to be used to constrain data entry to an allowed list one
  100. column may be all you need. The most common situation, however, is to have
  101. two columns, the first holding the allowed list and the second being an
  102. expansion or explanation of the former. Use the next row of the scrolling
  103. list to enter the column width and heading for the second table column.  It
  104. is possible to use very large and complex validation tables with all kinds
  105. of data associated with each item on the allowed list. There is room to
  106. specify 20 columns, but even this can be increased if necessary (see 14.6).
  107.  
  108. You can if you wish choose the foreground and background colours of both the
  109. heading and the body of your table by clicking repeatedly with SELECT or
  110. ADJUST on the Heading and Data icons. Whether this changes the foreground or
  111. background colour depends on which of the two radio buttons is selected. 
  112.  
  113. When you are satisfied with the data click Create and the table will be
  114. created and displayed. It is not saved on disc at this stage.  You may enter
  115. data into it now or later. Entries may be freely altered and overwritten.
  116. The table will be saved when you close the database or quit Powerbase but,
  117. if you want to play safe, click Force update on the keypad.
  118.  
  119. 5.4     Linking tables to fields
  120. --------------------------------
  121. To link your newly-created validation table to a field click MENU over the
  122. field and choose Link to table from the Field submenu. A pair of bump
  123. icons, with the usual pop-up menu alternative, lets you cycle through the
  124. tables in memory.  When you have the name of the required table displayed
  125. choose the column of the table to which the field is to be linked. It is
  126. recommended that column 0 normally provide the link (and therefore contains
  127. the data items for the allowed list) and this is set by default. You may,
  128. however, link to any column in the table and another pair of bump icons lets
  129. you cycle through the column numbers. 
  130.  
  131. Select Linked to table and click on OK. You will see that the foreground
  132. colour of the linked field has now  changed from black to green. Place the
  133. caret in the field and click on List values on the keypad. The validation
  134. table should be displayed.
  135.  
  136. You may link a validation table to a scrollable list.  The link is to a
  137. specified column of the list (make sure the pointer is over the required
  138. column when you click MENU) and, at present, only one column may be so
  139. linked: you can’t link two different validation tables to two columns of the
  140. same scrollable list.
  141.  
  142. 5.4.1   The Replace on entry feature
  143.  
  144. If you select this switch before linking the table a third pair of bump
  145. icons becomes active, allowing you to choose which column of the table will
  146. replace the data which you type in. In the F.E. college database referred to
  147. in 5.2 the short subject codes (e.g. CHE) would be in the first column and
  148. the longer names (e.g. Chemistry) in the second. On typing CHE <Return>
  149. Powerbase would replace it with Chemistry. In such cases both the entries in
  150. the allowed list proper and those in the replacement list are considered
  151. equally valid and either may be entered. You could actually type Chemistry
  152. if you wished, instead of just CHE, but the former would obviously take
  153. longer to enter and you are far more likely to make a mistake, in which case
  154. Powerbase would object. 
  155.  
  156. 5.4.2   When to turn off the Exact match switch
  157.  
  158. The Exact match switch is normally selected to indicate that the only user
  159. inputs which will be accepted are those which exactly match an entry on the
  160. allowed list.  Deselecting the switch allows you to type inputs which are
  161. longer, but not shorter, than the entries on the allowed list so long as the
  162. leftmost part of the input matches such an entry. The unmatched “tail” of
  163. your typed entry will be attached to the end of the replacement string. This
  164. feature is intended for use with the Replace on entry facility. Suppose your
  165. database records numbers of items called Widgets, Doodahs and Thingummies.
  166. You decide to identify these names with the codes W, D and T, put the codes
  167. in the first column of the table and the names in the second and select
  168.  
  169.                         - 37 -
  170.  
  171. Replace on entry. You can then type W <Return> and it will be replaced with
  172. Widgets. What you might want, however, is to type W7 and have it replaced
  173. with Widgets, 7.  Deselecting Exact match allows you to do just that since
  174. the W in W7 matches an entry in the validation list. The “expanded” entry in
  175. the second column is made to read “Widgets, ” (note the comma and space) and
  176. Powerbase tacks the unmatched part of your entry onto the end of this so
  177. that W7 is replaced with Widgets, 7.
  178.  
  179. 5.5     Displaying validation tables
  180. ------------------------------------
  181. Placing the mouse pointer over a linked record field and double-clicking
  182. with SELECT makes a small window pop up to the right of the field.  This
  183. shows all the data which is on the same row of the validation table as the
  184. linked item. The item from the allowed list is highlighted in green and the
  185. item (if any) to be substituted on entry is shown in red.  This feature is
  186. very useful if you are examining a database which uses coded data and you
  187. encounter a code which you haven’t seen before.  
  188.  
  189. You can also make this window appear automatically whenever the caret enters
  190. a linked field. To turn  the feature on choose Preferences from the iconbar
  191. menu and select the Display linked table data switch.
  192.  
  193. When linked to a field in the database record the complete table may be
  194. displayed by placing the caret in the linked field and clicking on the
  195. keypad button List values (F9). Alternatively, any table present in memory,
  196. whether linked to a data field or not, may be displayed by selecting it from
  197. the Display table submenu (reached from the Validation submenu). 
  198.  
  199. 5.6     The validation table menu
  200. ---------------------------------
  201. Clicking MENU over a displayed table offers a menu with entries as follows:−
  202.  
  203. Clear removes all data from the table, leaving it blank. Since wiping out a
  204. table in this way is pretty drastic you will be asked to confirm the
  205. operation before it actually takes place. It is possible to recover the
  206. table using Undo all provided the table has not been closed. When you close
  207. a database all the validation tables in memory are written to the disc so
  208. you will over-write your disc copy with the blank table.  
  209.  
  210. Modify brings up the same window as you used to create the table. You may
  211. then increase the number of rows, add extra columns, alter the order of
  212. existing columns or, indeed, do anything sensible. Be careful about renaming
  213. columns; combining this with shuffling the columns about is apt to cause
  214. confusion: Powerbase isn’t a mind-reader! When you have made the required
  215. changes click on  Modify. 
  216.  
  217. Print outputs the contents of a validation table in the same format as a
  218. report. The output appears in a window from which it may be saved as a text
  219. file (see 3.1.1). 
  220.  
  221. Sort <n> will sort the table on the nth column, that being the one the mouse
  222. pointer was over when you clicked MENU on the table.
  223.  
  224. Undo change will restore the specific item which you were pointing at when
  225. you clicked MENU to the state it was in when the table was displayed. You
  226. cannot undo changes if you have closed the table then re-displayed it.
  227.  
  228. Undo all restores the entire table to the state it was in when first
  229. displayed, even if Clear has been used. You cannot undo changes if you have
  230. closed the table then re-displayed it.
  231.  
  232. Save leads to a Save box in which the default pathname points to a directory
  233. called ValTables inside the database application directory. Since that’s
  234. where Powerbase expects to find the tables for a database you should
  235. normally accept this pathname by clicking on Save or typing Return. Only if
  236. you are transferring tables from one database to another should you need to
  237. drag the icon to a filer window. 
  238.  
  239. All validation tables in memory are, in any case, saved to the ValTables
  240. directory when you close the database or quit Powerbase and you can also
  241. make this happen at any time by clicking on Force update on the keypad. 
  242.  
  243. Save as CSV leads to a Save box from which the table contents can be saved
  244. as a CSV file. The default pathname points to the database’s PrintJobs
  245. directory.  The file can be loaded into a blank validation table of
  246. appropriate format by dropping the file onto the open table (see 8.4 for
  247. further details).
  248.  
  249.                                 - 38 -
  250.  
  251. 5.7     Loading validation tables
  252. ---------------------------------
  253. A table linked to a field is automatically loaded when the database is
  254. opened. If not yet linked, however, the table won’t be in memory unless you
  255. have just created it. To load the table choose Show files from the
  256. Validation submenu (Ctrl Q). The contents of the ValTables directory will be
  257. displayed and the required tables can dragged onto the record window (or
  258. simply double-clicked). As each table is loaded it will be displayed.
  259.  
  260. There may be times when you wishes to use a validation table to hold some
  261. data, but don’t want to use it to validate input into a field or to link it
  262. to a field at all. It is possible to load a validation table once the
  263. database is open by using the procedure described in the previous paragraph,
  264. but a more convenient solution is to add a “+” character to the end of the
  265. table’s name (the usual limit of 10 characters applies to the name length). 
  266. Powerbase will then load it whether any field is linked to it or not. 
  267.  
  268. 5.8     Including validation table data in printouts
  269. ----------------------------------------------------
  270. Validation tables are often used to allow short codes to be entered in
  271. records but with a link to a more descriptive entry in another column of the
  272. table.  If this is all that is required then always put the data which makes
  273. up the actual allowed list, i.e. the items which are allowed in the fields
  274. of the main record, into the first column of the table (column 0) and set
  275. the link from the record field to this column. The more detailed “expanded”
  276. entry should go in column 1. Printing with the Expand switch in the Print
  277. options window selected  will then print the column 1 instead of the column
  278. 0 entry. 
  279.  
  280. You can also include data from other columns of a table by displaying the
  281. table  and clicking in the required columns with ADJUST, exactly like
  282. selecting main record fields for printing (see 3.3). It is immaterial which
  283. row you click on; only the column matters and the highlighting to show which
  284. columns are selected always appears in the first row. The columns selected
  285. in all tables are saved as part of a print Selection file and may therefore
  286. be retrieved for future use. As well as highlighting the required columns
  287. you will also need to select the Expand switch as described above. Printed
  288. reports will then include all the data from the highlighted columns. You
  289. will need to use this method if you want to print columns 0 and 1 of a table
  290. instead of printing column 1 instead of column 0 as described in the
  291. previous paragraph.
  292.  
  293. 5.9     Entering validation table data into a record
  294. ----------------------------------------------------
  295. There is one more feature of validation tables which might prove useful.  If
  296. you place the caret in a database field and then double-click over an entry
  297. in an open validation table, the table entry will be copied into the data
  298. field, if it will fit. Nothing is copied if the item is too long to fit.
  299.  
  300.                                 - 39 -